package com.yochi.pictureseditor.tools;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;

public class SettingsManager {
	
	private static final String APPLICATION_PREFERENCES = "fr.yochi.pictureseditor.preferences";
	
	// parameters
	private static boolean zoomEnabled;
	private static boolean labelEnabled;
	
	public static void setZoomEnabled(Context context, boolean value) {
		zoomEnabled = value;
		saveSettings(context);
	}
	
	public static boolean isZoomEnabled() {
		return zoomEnabled;
	}
	
	public static void setLabelEnabled(Context context, boolean value) {
		labelEnabled = value;
		saveSettings(context);
	}
	
	public static boolean isLabelEnabled() {
		return labelEnabled;
	}
	
	public static boolean shouldEnableLabel(Context context) {
		Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		int orientation = display.getRotation();
		return (labelEnabled==true && (orientation==Surface.ROTATION_0 || orientation==Surface.ROTATION_180));
	}
	
	
	  ///////////////////
	 // LOAD SETTINGS //
	///////////////////
	
	public static void loadSettings(Context context) {
		SharedPreferences prefs = context.getSharedPreferences(APPLICATION_PREFERENCES, Context.MODE_PRIVATE);
		zoomEnabled = prefs.getBoolean("zoomEnabled", true);
		labelEnabled = prefs.getBoolean("labelEnabled", true);
	}
	
	
	///////////////////
	// SAVE SETTINGS //
	///////////////////
	
	private static void saveSettings(Context context) {
		SharedPreferences.Editor editor = context.getSharedPreferences(APPLICATION_PREFERENCES, Context.MODE_PRIVATE).edit();
		editor.putBoolean("zoomEnabled", zoomEnabled);
		editor.putBoolean("labelEnabled", labelEnabled);
		editor.commit();
	}

}
